<link rel="stylesheet" type="text/css" href="/static/admin/plugins/bootstrap-fileinput/css/fileinput.min.css">
<link rel="stylesheet" type="text/css" href="/static/admin/plugins/bootstrap-select/dist/css/bootstrap-select.min.css">
<div class="page-header clearfix">
    <div class="pull-left">
        <h4 class="mt-0 mb-5">友情链接修改</h4>
        <ol class="breadcrumb mb-0">
            <li><a href="javascript:;">你可以对商品标签进行友情链接修改</a></li>
        </ol>
    </div>
</div>
<div class="main-content container-fluid">
    <div class="widget">
        <div class="widget-heading">
            <h3 class="widget-title">友情链接修改</h3>
        </div>
        <div class="widget-body">
            <form id="form-vertical" method="post" action="{:url('admin/link/edit')}" novalidate="novalidate">
                <div class="form-group">
                    <label>网站名称</label>
                    <input value="{$shop->name}" type="text" name="name" placeholder="请输入友情链接名称" data-messages="请输入友情链接名称" data-rule-required="true" class="form-control">
                </div>
                <div class="form-group">
                    <label>网站链接</label>
                    <input value="{$shop->url}" type="text" name="url" placeholder="请输入链接" data-messages="请输入链接" data-rule-required="true" class="form-control">
                </div>
                <div class="form-group">
                    <label>网站图标</label>
                    <input type="file" id="uploadImg" name="file" language="zh" >
                </div>
                <div class="form-group">
                    <label>当前状态</label>
                    <select name="row_status" class="form-control">
                        <option value="">请选择</option>
                        <option value="0">待审核</option>
                        <option value="1">通过</option>
                        <option value="-1">拒绝</option>
                    </select>
                </div>
                <input type="hidden" name="thumb" value="{$shop->thumb}" id="thumb">
                <input type="hidden" name="type" value="save">
                <input type="hidden" name="id" value="{$shop->id}">
                <button type="submit" name="btnSubmit" class="btn btn-raised btn-black btn-block">
                    修改友情链接
                </button>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript" src="/static/admin/plugins/bootstrap-fileinput/js/plugins/canvas-to-blob.min.js"></script>
<script type="text/javascript" src="/static/admin/plugins/bootstrap-fileinput/js/fileinput.min.js"></script>
<script type="text/javascript" src="/static/admin/plugins/bootstrap-select/dist/js/bootstrap-select.min.js"></script>
<script type="text/javascript" src="/static/admin/plugins/bootstrap-fileinput/js/zh.js"></script>
<script type="text/javascript" src="/static/admin/plugins/jquery-validation/dist/jquery.validate.min.js"></script>
<script type="text/javascript" src="/static/admin/plugins/jquery-validation/dist/additional-methods.min.js"></script>
<script>
    var token = '{$qiniu_token}';
    $(function () {
        $("select[name=row_status]").val({$shop->row_status});
        $("#uploadImg").fileinput({
            language:'zh',
            uploadUrl: 'http://upload.qiniu.com/',
            allowedFileExtensions: ['jpg', 'png', 'gif', 'bmp'],
            maxFileSize: 1000,
            maxFilesNum: 1,
            uploadExtraData:{
                token : token

            },
            initialPreviewConfig:[
                {
                    url: '{:url('admin/api/delQiniuRes')}?url={:urlencode($shop->thumb)}',
                    caption: '{$shop->name}'
                }
            ],
            initialPreview: [
                "<img src='{$shop->thumb}' class='file-preview-image' alt='Desert' title='Desert'>",
            ]

    }).on('fileuploaded',function (event,data) {

            if(!data.response){
                layer.msg('上传失败！',{
                    icon : 1,
                    time :1000
                });
                return false;
            }

            $("#thumb").val(data.response.hash);
            token = ajax.getQiniuUploadToken();
        });

        $("#form-vertical").validate({
            highlight:function(r){
                $(r).closest(".form-group").addClass("has-error")
            },
            rules:{
                name:{
                    required : true
                },
                url:{
                    required : true
                }
            },
            messages:{
                name:{
                    required : '不能为空'
                },
                url:{
                    required : '不能为空'
                }
            },
            unhighlight:function(r){
                $(r).closest(".form-group").removeClass("has-error")
            },
            errorElement:"span",
            errorClass:"help-block",
            errorPlacement:function(r,e){
                e.parent(".input-group").length?r.insertAfter(e.parent()):e.parent("label").length?r.insertBefore(e.parent()):r.insertAfter(e)
            },
            submitHandler: function (form) {
                Pace.restart();
                ajax.formSubmit('#form-vertical',function (data) {
                    if(data.err){
                        layer.msg(data.msg,{
                            icon:2,
                            time:1000
                        });
                        return false;
                    }
                    layer.msg(data.msg,{
                        icon:1,
                        time:1000
                    });
                    setTimeout(function () {
                        $('a[_href="{:url('admin/link/index')}"]').click();
                    },1000);
                });
                return false;
            }
        });
    });
</script>